# encoding=utf-8

import numpy as np

a = np.array([1, 2, 3, 4])
b = np.arange(10, 50, 10)
print("a=", a, "\nb=", b)
result = a+b
print("a+b=", result)
result = a-b
print("a-b=", result)
result = a * b
print("a*b=", result)
result = a / b
print("a/b=", result)
result = a ** 2
print("a**2=", result)
result = 10 * np.sin(a)
print("10*sin(a)=", result)

print(a < 3)

c = np.arange(1, 5, 1).reshape([2, 2])
d = np.array([[1, 2], [3, 4]])
print("c=", c)
print("d=", d)
result = c + d
print("c+d=", result)
result = c * d
print("c*d=", result)
result = np.dot(c, d)
print("dot(c,d)=", result)
result = c.dot(d)
print("c.dot(d)=", result)

e = np.random.random((2, 4))
print(e)
e = np.random.random_sample()
print(e)
e = np.random.random_sample((3,))
print(e)

result = np.sum(e)
print(result)
result = np.min(e)
print(result)
result = np.max(e)
print(result)
print(np.argmin(e))  # 最小值的索引
print(np.argmax(e))  # 最大值的索引


array = np.arange(2, 14).reshape((3, 4))
print(array)
print("min=", np.min(array))
print("max=", np.max(array))
print("sum=", np.sum(array))
print("min index= ", np.argmin(array))
print("max index=", np.argmax(array))
print("array mean= ", np.mean(array))
print("array mean= ", array.mean())
print("array average=", np.average(array))
print("array cumsum=", np.cumsum(array))  # 累加：生成的每一项矩阵元素均是从原矩阵首项累加到对应项的元素之和
print("array diff=", np.diff(array))  # 累差：每一行中后一项与前一项之差
print("array nonzero=", np.nonzero(array))  # 将所有非零元素的行与列坐标分割开，重构成两个分别关于行和列的矩阵。

A = np.arange(14, 2, -1).reshape((3, 4))
print("A=", A)
print("sort(A)=", np.sort(A))  # 这里的排序函数仍然仅针对每一行进行从小到大排序操作
# 矩阵的转置有两种表示方法：
print("transpose(A)=", np.transpose(A))
print("A.T=", A.T)
print("clip(A, 5, 9)=", np.clip(A, 5, 10))  # 让函数判断矩阵中元素是否有比最小值小的或者比最大值大的元素，并将这些指定的元素转换为最小值或者最大值

